{% extends 'pages/_base.html' %}
{% from 'tools/card.html' import nonModal %}
{% from 'tools/table.html' import table %}

{% block _base %}

{% set review_data = [] %}
{% for row in data.Blog %}
    {% set _ = review_data.append({
        'id': '<a href="' ~ url_for("post.get_anyone_page_of_blog", pid=row.id) ~ '">' ~ row.id ~ '</a>',
        'pass':
            '<form action="' ~ url_for("post.post_anyone_service_of_pass_blog", pid=row.id) ~ '" method="POST" onsubmit="return handleSubmit(event, this)">'
            ~ '<button type="submit" class="btn btn-sm btn-success" style="height: 32px;">通过</button>'
            ~ '</form>',
        'unpass':
            '<form action="' ~ url_for("post.post_anyone_service_of_unpass_blog", pid=row.id) ~ '" method="POST" onsubmit="return handleUnpassSubmit(event, this)">'
            ~ '<input type="text" name="reason" placeholder="填写理由" required style="height: 32px; min-width: 300px;">'
            ~ '<button type="submit" class="btn btn-sm btn-danger" style="height: 32px;">不通过</button>'
            ~ '</form>',
    }) %}
{% endfor %}

<script>
function handleSubmit(event, form) {
    event.preventDefault();

    const url = form.action;
    fetchPost(url, {}).then(json => {
        flash(json.msg)
    })
}

// 处理不通过按钮提交
function handleUnpassSubmit(event, form) {
    event.preventDefault();

    const url = form.action;
    const reason = form.querySelector('input[name="reason"]').value;
    const data = { 'reason':reason };
    fetchPost(url, data).then(json => {flash(json.msg)})
}


</script>

{% if data.checkable %}

{{ nonModal(
    head='<h4>帖子审核</h4>',
    collapse=False,
    body=table(
        required={'id': '帖子ID', 'pass': '通过', 'unpass': '不通过'},
        data=review_data
    )
) }}

{% else %}
<h3>您暂无审核权限</h3>
{% endif %}


{% endblock %}
